##Diff in Diff for Republicans and Democrats
####Figure 1
dem<-c(2.53, 2.98, 2.87, 2.79, 2.67, 2.77, 2.90, 3.00, 2.93, 3.10, 3.25)
rep<-c(2.98, 2.77, 2.57, 2.55, 2.91, 2.79, 2.85, 2.35, 2.60, 2.85, 2.80)
did<-c(-.665, -.086, .065, .468, -.213, -.069, -.597, .316, .079, -.207)

plot(-1000, -1000, xlim=c(1,11), ylim=c(2,4), xlab="Month", ylab="Diffuse Support", axes=F)

axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3, 3.5, 4), labels=c("2.0", "2.5", "3.0", "3.5", "4.0"))


lines(c(1:11), dem, lty=1, col="blue")
lines(c(1:11), rep, lty=2, col="red")

box()

text(1.6, 3.5, "-0.665*" ,cex=.8)
text(2.4, 2.3, "-0.086",cex=.8)
text(3.6, 3.5, "0.065",cex=.8)
text(4.4, 2.3, "0.468*",cex=.8)
text(5.6, 3.5, "-0.213",cex=.8)
text(6.4, 2.3, "-0.069",cex=.8)
text(7.6, 3.5, "-0.597*",cex=.8)
text(8.4, 2.3, "0.316",cex=.8)
text(9.6, 3.5, "0.079",cex=.8)
text(10.4, 2.3, "-0.207",cex=.8)

points(c(1:11), dem, col="blue", pch=19)
points(c(1:11), rep, col="red", pch=17)

legend("topright", c("Democrats", "Republicans"), lty=c(1:2), col=c("blue","red"), cex=1, pch=c(19,17))

arrows(1.6, 3.4, 1.6, 2.9)
arrows(2.4, 2.4, 2.4, 2.6)
arrows(3.6, 3.4, 3.6, 2.9)
arrows(4.4, 2.4, 4.4, 2.6)
arrows(5.6, 3.4, 5.6, 2.9)
arrows(6.4, 2.4, 6.4, 2.8)
arrows(7.6, 3.4, 7.6, 3.0)
arrows(8.4, 2.33, 8.4, 2.45)
arrows(9.6, 3.4, 9.6, 3.1)
arrows(10.4, 2.4, 10.4, 2.8)


###Ideology
###Figure E1
lib<-c(2.953, 3.303, 3.276, 3.157, 3.060, 3.196, 3.348, 3.544, 3.431, 3.597, 3.712)
con<-c(3.035, 2.995, 2.663, 2.675, 2.937, 2.856, 2.848, 2.338, 2.613, 2.845, 2.819)
did_id<-c(-.331, -.301, .094, .306, -.176, -.130, -.580, .349, .065, -.137)

plot(-1000, -1000, xlim=c(1,11), ylim=c(2,4), xlab="Month", ylab="Diffuse Support", axes=F)

axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3, 3.5, 4), labels=c("2.0", "2.5", "3.0", "3.5", "4.0"))


lines(c(1:11), lib, lty=1, col="blue")
lines(c(1:11), con, lty=2, col="red")

text(1.6, 4, "-0.390*" ,cex=.8)
text(2.4, 2, "-0.306",cex=.8)
text(3.6, 4, "0.131",cex=.8)
text(4.4, 2, "0.359",cex=.8)
text(5.6, 4, "-0.217",cex=.8)
text(6.4, 2, "-0.160",cex=.8)
text(7.6, 4, "-0.706*",cex=.8)
text(8.4, 2, "0.389*",cex=.8)
text(9.6, 4, "0.065",cex=.8)
text(10.4, 2, "-0.141",cex=.8)

points(c(1:11), lib, col="blue", pch=19)
points(c(1:11), con, col="red", pch=17)

legend(9,3.2, c("Liberals", "Conservatives"), lty=c(1:2), col=c("blue","red"), cex=.9, pch=c(19,17))


arrows(1.6, 3.9, 1.6, 3.3)
arrows(2.4, 2.1, 2.4, 2.7)
arrows(3.6, 3.9, 3.6, 3.4)
arrows(4.4, 2.1, 4.4, 2.7)
arrows(5.6, 3.9, 5.6, 3.3)
arrows(6.4, 2.1, 6.4, 2.7)
arrows(7.6, 3.9, 7.6, 3.5)
arrows(8.4, 2.1, 8.4, 2.3)
arrows(9.6, 3.9, 9.6, 3.7)
arrows(10.4, 2.1, 10.4, 2.7)
box()

###All movement. Figure D1
all<-c(2.28, 2.47, 2.20, 2.28, 2.24, 2.21, 2.37, 2.21, 2.23, 2.48, 2.52)
all_se<-c(.06, .06, .06, .05, .06, .06, .06, .06, .05, .06, .06)
all_low<-all-1.97*all_se
all_hi<-all+1.97*all_se

plot(-1000, -1000, xlim=c(1,11), ylim=c(1.9,3), xlab="Month", ylab="Diffuse Support", axes=F)

axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3), labels=c("2.0", "2.5", "3.0"))

points(c(1:11), all, pch=19, col="black")

for(i in 1:11){
  segments(i, all_hi[i], i,all_low[i], col="black")
}
lines(c(1:11), all)
box()


###Movement for Ideologues Figure D4
liberals<-c(2.59, 2.91, 2.82, 2.66, 2.61, 2.72, 2.89, 3.05, 2.98, 3.11, 3.42)
conservatives<-c(2.63, 2.70, 2.19, 2.50, 2.50, 2.32, 2.46, 2.00, 2.13, 2.56, 2.28)
lib_se<-c(.098, .107, .096, .097, .096, .098, .102, .108, .112, .100, .102, .102)
con_se<-c(.089, .098, .093, .093, .088, .094, .095, .099, .093, .084, .090, .087)

plot(-1000, -1000, xlim=c(1,11), ylim=c(1.9,4), xlab="Month", ylab="Diffuse Support", axes=F)

axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3, 3.5, 4), labels=c("2.0", "2.5", "3.0", "3.5", "4.0"))

points(c(1:11), liberals, pch=19, col="blue")
points(c(1:11), conservatives, pch=15, col="red")
for(i in 1:11){
  segments(i, liberals[i]+1.97*lib_se[i], i,liberals[i]-1.97*lib_se[i], col="blue")
  segments(i, conservatives[i]+1.97*con_se[i], i,conservatives[i]-1.97*con_se[i], col="red")
}
box()
(legend("topleft", c("Liberals", "Conservatives"), pch=c(19,15), lty=1, col=c("blue", "red")))




library(ggplot2)
library(descr)
library(RColorBrewer)
library(foreign)
data<-read.dta("C:\\Users\\ptucker\\Dropbox\\Supreme Court Panel\\Replication\\merged_replication_data_NT.dta")

cols <- brewer.pal(5, "Pastel2")

SCT1<-subset(data, select=c(as.numeric(SCT1S6),as.numeric(SCT1S8), as.numeric(SCT1S14), as.numeric(SCT1S14a), as.numeric(SCT1S20), as.numeric(SCT1S32), as.numeric(GN1S34), as.numeric(SCT1S38), as.numeric(SCT1S42), as.numeric(SCT1S44), as.numeric(SCT1S50), as.numeric(SCT1S52), as.numeric(SCT1S54), as.numeric(SCT1S56)))
####SCT1
SCT1_STR_AGR<-c(crosstab(data$SCT1S6, data$SCT1S6, plot=F, prop.t=T)$prop.tbl[1],crosstab(data$SCT1S8, data$SCT1S8, plot=F, prop.t=T)$prop.tbl[1],crosstab(data$SCT1S14, data$SCT1S14, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S20, data$SCT1S20, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S32, data$SCT1S32, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S38, data$SCT1S38, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S42, data$SCT1S42, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S44, data$SCT1S44, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S50, data$SCT1S50, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S52, data$SCT1S52, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S54, data$SCT1S54, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT1S56, data$SCT1S56, plot=F, prop.t=T)$prop.tbl[1])

SCT1_SMW_AGR<-c(crosstab(data$SCT1S6, data$SCT1S6, plot=F, prop.t=T)$prop.tbl[7],crosstab(data$SCT1S8, data$SCT1S8, plot=F, prop.t=T)$prop.tbl[7],crosstab(data$SCT1S14, data$SCT1S14, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S20, data$SCT1S20, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S32, data$SCT1S32, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S38, data$SCT1S38, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S42, data$SCT1S42, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S44, data$SCT1S44, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S50, data$SCT1S50, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S52, data$SCT1S52, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S54, data$SCT1S54, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT1S56, data$SCT1S56, plot=F, prop.t=T)$prop.tbl[7])

SCT1_NEITHER<-c(crosstab(data$SCT1S6, data$SCT1S6, plot=F, prop.t=T)$prop.tbl[13],crosstab(data$SCT1S8, data$SCT1S8, plot=F, prop.t=T)$prop.tbl[13],crosstab(data$SCT1S14, data$SCT1S14, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S20, data$SCT1S20, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S32, data$SCT1S32, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S38, data$SCT1S38, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S42, data$SCT1S42, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S44, data$SCT1S44, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S50, data$SCT1S50, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S52, data$SCT1S52, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S54, data$SCT1S54, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT1S56, data$SCT1S56, plot=F, prop.t=T)$prop.tbl[13])

SCT1_SMW_DIS<-c(crosstab(data$SCT1S6, data$SCT1S6, plot=F, prop.t=T)$prop.tbl[19],crosstab(data$SCT1S8, data$SCT1S8, plot=F, prop.t=T)$prop.tbl[19],crosstab(data$SCT1S14, data$SCT1S14, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S20, data$SCT1S20, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S32, data$SCT1S32, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S38, data$SCT1S38, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S42, data$SCT1S42, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S44, data$SCT1S44, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S50, data$SCT1S50, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S52, data$SCT1S52, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S54, data$SCT1S54, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT1S56, data$SCT1S56, plot=F, prop.t=T)$prop.tbl[19])

SCT1_STR_DIS<-c(crosstab(data$SCT1S6, data$SCT1S6, plot=F, prop.t=T)$prop.tbl[25],crosstab(data$SCT1S8, data$SCT1S8, plot=F, prop.t=T)$prop.tbl[25],crosstab(data$SCT1S14, data$SCT1S14, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S20, data$SCT1S20, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S32, data$SCT1S32, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S38, data$SCT1S38, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S42, data$SCT1S42, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S44, data$SCT1S44, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S50, data$SCT1S50, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S52, data$SCT1S52, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S54, data$SCT1S54, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT1S56, data$SCT1S56, plot=F, prop.t=T)$prop.tbl[25])

###SCT1 D2, left panel
plot(-2,-2, xlim=c(6, 56), ylim=c(0,1), xaxt="n", yaxt="n", ylab="", xlab="Wave", axes=F, main="Do Away with Court", cex.main=1.4)
mtext(c("5/12","7/12","1/13","7/13","7/14",  "1/15","5/15", "7/15", "1/16", "3/16", "5/16", "7/16" ), at=c(6,8,14,20,32,  38,42, 44, 50, 52, 54, 56), side=1, line=0, cex=.4)
x <- c(6,8,14,20,32,  38,42, 44, 50, 52, 54, 56)

DO_AWAY_VIEWS <-cbind(SCT1_STR_AGR, SCT1_SMW_AGR, SCT1_NEITHER, SCT1_SMW_DIS, SCT1_STR_DIS )


lines(x, DO_AWAY_VIEWS[,5]) 
lines(x, DO_AWAY_VIEWS[,4]+ DO_AWAY_VIEWS[,5])
lines(x, DO_AWAY_VIEWS[,3]+DO_AWAY_VIEWS[,4]+ DO_AWAY_VIEWS[,5])
lines(x, DO_AWAY_VIEWS[,2] +DO_AWAY_VIEWS[,3]+DO_AWAY_VIEWS[,4]+ DO_AWAY_VIEWS[,5])

xx<-c(x, rev(x))
y1<-c(rep(0,12), rev(DO_AWAY_VIEWS[,5]))
polygon(xx,y1, col="#B3E2CD")
yy2<-c(DO_AWAY_VIEWS[,5],rev(DO_AWAY_VIEWS[,5])+rev(DO_AWAY_VIEWS[,4]))
polygon(xx,yy2, col=cols[2] )
yy3<-c(DO_AWAY_VIEWS[,5]+ DO_AWAY_VIEWS[,4], rev(DO_AWAY_VIEWS[,5])+rev(DO_AWAY_VIEWS[,4])+rev(DO_AWAY_VIEWS[,3]))
polygon(xx,yy3, col=cols[3] )
yy4<-c(DO_AWAY_VIEWS[,5]+ DO_AWAY_VIEWS[,4]+DO_AWAY_VIEWS[,3], rev(DO_AWAY_VIEWS[,5])+rev(DO_AWAY_VIEWS[,4])+rev(DO_AWAY_VIEWS[,3])+rev(DO_AWAY_VIEWS[,2]))
polygon(xx,yy4, col=cols[4] )
yy5<-c(DO_AWAY_VIEWS[,5]+ DO_AWAY_VIEWS[,4]+DO_AWAY_VIEWS[,3]+DO_AWAY_VIEWS[,2], rev(DO_AWAY_VIEWS[,5])+rev(DO_AWAY_VIEWS[,4])+rev(DO_AWAY_VIEWS[,3])+rev(DO_AWAY_VIEWS[,2])+rev(DO_AWAY_VIEWS[,1]))

polygon(xx,yy5, col=cols[5] )
par("usr")[1]

mtext(c("Strongly Agree", "Somewhat Agree", "Neither", "Somewhat Disagree", "Strongly Disagree"), at=c(.99, .92, .75, .5, .15 ), par("usr")[3], side=2, cex=.4, las=2)


####SCT3, D2 Right Panel
SCT3_STR_AGR<-c(crosstab(data$SCT3S6, data$SCT3S6, plot=F, prop.t=T)$prop.tbl[1],crosstab(data$SCT3S8, data$SCT3S8, plot=F, prop.t=T)$prop.tbl[1],crosstab(data$SCT3S14, data$SCT3S14, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S20, data$SCT3S20, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S32, data$SCT3S32, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S38, data$SCT3S38, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S42, data$SCT3S42, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S44, data$SCT3S44, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S50, data$SCT3S50, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S52, data$SCT3S52, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S54, data$SCT3S54, plot=F, prop.t=T)$prop.tbl[1], crosstab(data$SCT3S56, data$SCT3S56, plot=F, prop.t=T)$prop.tbl[1])

SCT3_SMW_AGR<-c(crosstab(data$SCT3S6, data$SCT3S6, plot=F, prop.t=T)$prop.tbl[7],crosstab(data$SCT3S8, data$SCT3S8, plot=F, prop.t=T)$prop.tbl[7],crosstab(data$SCT3S14, data$SCT3S14, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S20, data$SCT3S20, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S32, data$SCT3S32, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S38, data$SCT3S38, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S42, data$SCT3S42, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S44, data$SCT3S44, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S50, data$SCT3S50, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S52, data$SCT3S52, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S54, data$SCT3S54, plot=F, prop.t=T)$prop.tbl[7], crosstab(data$SCT3S56, data$SCT3S56, plot=F, prop.t=T)$prop.tbl[7])

SCT3_NEITHER<-c(crosstab(data$SCT3S6, data$SCT3S6, plot=F, prop.t=T)$prop.tbl[13],crosstab(data$SCT3S8, data$SCT3S8, plot=F, prop.t=T)$prop.tbl[13],crosstab(data$SCT3S14, data$SCT3S14, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S20, data$SCT3S20, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S32, data$SCT3S32, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S38, data$SCT3S38, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S42, data$SCT3S42, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S44, data$SCT3S44, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S50, data$SCT3S50, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S52, data$SCT3S52, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S54, data$SCT3S54, plot=F, prop.t=T)$prop.tbl[13], crosstab(data$SCT3S56, data$SCT3S56, plot=F, prop.t=T)$prop.tbl[13])

SCT3_SMW_DIS<-c(crosstab(data$SCT3S6, data$SCT3S6, plot=F, prop.t=T)$prop.tbl[19],crosstab(data$SCT3S8, data$SCT3S8, plot=F, prop.t=T)$prop.tbl[19],crosstab(data$SCT3S14, data$SCT3S14, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S20, data$SCT3S20, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S32, data$SCT3S32, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S38, data$SCT3S38, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S42, data$SCT3S42, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S44, data$SCT3S44, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S50, data$SCT3S50, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S52, data$SCT3S52, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S54, data$SCT3S54, plot=F, prop.t=T)$prop.tbl[19], crosstab(data$SCT3S56, data$SCT3S56, plot=F, prop.t=T)$prop.tbl[19])

SCT3_STR_DIS<-c(crosstab(data$SCT3S6, data$SCT3S6, plot=F, prop.t=T)$prop.tbl[25],crosstab(data$SCT3S8, data$SCT3S8, plot=F, prop.t=T)$prop.tbl[25],crosstab(data$SCT3S14, data$SCT3S14, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S20, data$SCT3S20, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S32, data$SCT3S32, plot=F, prop.t=T)$prop.tbl[25],  crosstab(data$SCT3S38, data$SCT3S38, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S42, data$SCT3S42, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S44, data$SCT3S44, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S50, data$SCT3S50, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S52, data$SCT3S52, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S54, data$SCT3S54, plot=F, prop.t=T)$prop.tbl[25], crosstab(data$SCT3S56, data$SCT3S56, plot=F, prop.t=T)$prop.tbl[25])

####SCT3
plot(-2,-2, xlim=c(6, 56), ylim=c(0,1), xaxt="n", yaxt="n", ylab="", xlab="Wave", axes=F, main="Too Mixed Up in Politics", cex.main=1.4)
mtext(c("5/12","7/12","1/13","7/13","7/14",  "1/15","5/15", "7/15", "1/16", "3/16", "5/16", "7/16" ), at=c(6,8,14,20,32,  38,42, 44, 50, 52, 54, 56), side=1, line=0, cex=.4)
x <- c(6,8,14,20,32,  38,42, 44, 50, 52, 54, 56)

MIXED_VIEWS <-cbind(SCT3_STR_AGR, SCT3_SMW_AGR, SCT3_NEITHER, SCT3_SMW_DIS, SCT3_STR_DIS )


lines(x, MIXED_VIEWS[,5]) 
lines(x, MIXED_VIEWS[,4]+ MIXED_VIEWS[,5])
lines(x, MIXED_VIEWS[,3]+MIXED_VIEWS[,4]+ MIXED_VIEWS[,5])
lines(x, MIXED_VIEWS[,2] +MIXED_VIEWS[,3]+MIXED_VIEWS[,4]+ MIXED_VIEWS[,5])

xx<-c(x, rev(x))
y1<-c(rep(0,12), rev(MIXED_VIEWS[,5]))
polygon(xx,y1, col="#B3E2CD")
yy2<-c(MIXED_VIEWS[,5],rev(MIXED_VIEWS[,5])+rev(MIXED_VIEWS[,4]))
polygon(xx,yy2, col=cols[2] )
yy3<-c(MIXED_VIEWS[,5]+ MIXED_VIEWS[,4], rev(MIXED_VIEWS[,5])+rev(MIXED_VIEWS[,4])+rev(MIXED_VIEWS[,3]))
polygon(xx,yy3, col=cols[3] )
yy4<-c(MIXED_VIEWS[,5]+ MIXED_VIEWS[,4]+MIXED_VIEWS[,3], rev(MIXED_VIEWS[,5])+rev(MIXED_VIEWS[,4])+rev(MIXED_VIEWS[,3])+rev(MIXED_VIEWS[,2]))
polygon(xx,yy4, col=cols[4] )
yy5<-c(MIXED_VIEWS[,5]+ MIXED_VIEWS[,4]+MIXED_VIEWS[,3]+MIXED_VIEWS[,2], rev(MIXED_VIEWS[,5])+rev(MIXED_VIEWS[,4])+rev(MIXED_VIEWS[,3])+rev(MIXED_VIEWS[,2])+rev(MIXED_VIEWS[,1]))

polygon(xx,yy5, col=cols[5] )
par("usr")[1]

mtext(c("Strongly Agree", "Somewhat Agree", "Neither", "Somewhat Disagree", "Strongly Disagree"), at=c(.99, .82, .45, .15, .03 ), par("usr")[3], side=2, cex=.4, las=2)

####Movement for Partisans, Figure D3
dem_diffuse_mean<-c(1.929451, 2.512183, 2.331303, 2.300707, 2.164773, 2.134064, 2.362788, 2.416014, 2.23664, 2.545337, 2.778623, 2.572386, 2.374809)
dem_diffuse_lower<-c(1.754927, 2.342943, 2.162463, 2.130233, 1.992557, 1.955093, 2.176276, 2.215424, 2.061257, 2.363451, 2.58995, 2.3755, 2.175995)
dem_diffuse_higher<-c(2.103976, 2.681424, 2.500143, 2.471182, 2.33699, 2.313035, 2.549301, 2.616604, 2.412023, 2.727223, 2.967296, 2.769272, 2.573623)
rep_diffuse_mean<-c(2.800279, 2.58505, 2.2002295, 2.462162, 2.580273, 2.36027, 2.47583, 2.142015, 2.177956, 2.429184, 2.293038, 2.72347, 2.839986)
rep_diffuse_lower<-c(2.578099, 2.36806, 1.990487, 2.255784, 2.358105, 2.140974, 2.242489, 1.91262, 1.988755, 2.229725, 2.088364, 2.501854, 2.617002)
rep_diffuse_higher<-c(3.02246, 2.80204, 2.414103, 2.668541, 2.802441, 2.579566, 2.709171, 2.371409, 2.367157, 2.628643, 2.497711, 2.945086, 3.062971)

months<-c(1:13)
plot(-1,-1, xlim=c(0,12), ylim=c(1.5, 3.5), main="", xlab="Wave", ylab="Mean Level of Support", axes=F)
axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3, 3.5, 4), labels=c("2.0", "2.5", "3.0", "3.5", "4.0"))
points(c(1:11), dem_diffuse_mean[1:11], col="blue", pch=19)
points(c(1:11), rep_diffuse_mean[1:11], col="red", pch=17)
lines(c(1:11), dem_diffuse_mean[1:11], col="blue" )
lines(c(1:11), rep_diffuse_mean[1:11], col="red" )
segments(c(1:11), dem_diffuse_lower[1:11], months[1:11], dem_diffuse_higher[1:11], col="blue")
segments(c(1:11), rep_diffuse_lower[1:11], months[1:11], rep_diffuse_higher[1:11], col="red")
legend("topleft", c("Democrats", "Republicans"), lty=c(1,1), pch=c(19,17), col=c("blue", "red"), bty="n")
box()

###Movement for Ideologues, Figure D4
liberals<-c(2.59, 2.91, 2.82, 2.66, 2.61, 2.72, 2.89, 3.05, 2.98, 3.11, 3.42)
conservatives<-c(2.63, 2.70, 2.19, 2.50, 2.50, 2.32, 2.46, 2.00, 2.13, 2.56, 2.28)
lib_se<-c(.098, .107, .096, .097, .096, .098, .102, .108, .112, .100, .102, .102)
con_se<-c(.089, .098, .093, .093, .088, .094, .095, .099, .093, .084, .090, .087)

plot(-1000, -1000, xlim=c(1,11), ylim=c(1.9,4), xlab="Month", ylab="Diffuse Support", axes=F)

axis(1, at=c(1:11), labels=c("5/12", "7/12", "1/13", "7/13", "7/14", "1/15", "5/15", "7/15", "1/16", "3/16", "7/16"))
axis(2, at=c(2, 2.5, 3, 3.5, 4), labels=c("2.0", "2.5", "3.0", "3.5", "4.0"))

points(c(1:11), liberals, pch=19, col="blue")
points(c(1:11), conservatives, pch=15, col="red")
for(i in 1:11){
  segments(i, liberals[i]+1.97*lib_se[i], i,liberals[i]-1.97*lib_se[i], col="blue")
  segments(i, conservatives[i]+1.97*con_se[i], i,conservatives[i]-1.97*con_se[i], col="red")
}
box()
(legend("topleft", c("Liberals", "Conservatives"), pch=c(19,15), lty=1, col=c("blue", "red")))

#Figure 5, Specific Support
months<-c(1:59)

##Democrats
total_specific_support_dems<-c(52.16,55.81, 50.01, 53.09, 47.49, 43.95, 48.81, 60.96, 63.92, 52.44, 63.72, 54.25,53.57,54.38, 63.08, 50.94, 58.88, 52.14, 54.49, 54.07, 48.58, 47.44, 52.21, 50.16, 44.50, 47.14, 43.99, 53.28, 38.70, 44.84, 46.61, 43.81, 44.17, 49.99, 43.07, 50.02, 40.42, 42.75, 44.37, 49.09, 48.18, 49.89, 45.94, 62.91, 54.26, 51.1, 49.15, 53.26, 49.59, 51.81, 55.14, 47.38, 47.16, 50.78, 54.58, 51.99, 57.08, 54.54, 50.00)
total_specific_opposition_dems<-c(29.58, 26.34, 24.24, 27.26, 27.29, 37.99, 32.92, 24.69, 18.91, 36.0, 16.99, 26.3, 32.45, 31.72, 25.83,27.55, 28.79, 29.67, 30.76, 30.13, 37.20, 26.96, 28.64, 26.36, 34.67, 32.14, 32.47, 31.05, 42.67, 40.02, 35.73, 39.31, 37.62, 35.00, 38.72, 32.51, 38.23, 37.54, 34.69, 27.54, 38.39, 31.46, 33.16, 25.45, 30.81, 33.08, 32.5, 30.61, 32.46, 29.26, 29.78, 25.20, 31.34, 33.54, 30.11, 28.96, 27.53, 29.22, 35.21)
#Republicans
total_specific_support_reps<-c(54.88, 48.62, 50.46, 48.58, 64.18, 52.08, 49.98, 39.91, 50.70, 51.05, 41.44,43.80, 43.08,47.73,43.42,38.05, 36.01, 30.97,43.20, 31.35, 42.49, 35.82, 28.74, 32.46, 31.17, 34.60, 38.04, 33.65, 42.39, 34.06, 40.42, 39.29, 47.34, 42.57, 48.91, 43.20, 44.93, 45.44, 42.33, 41.04, 45.07, 37.53, 36.58, 24.04, 24.41, 31.55, 36.82, 35.43, 33.29, 32.68, 39.14, 42.14, 34.10, 34.14, 39.42, 26.15, 38.63, 31.80, 40.67)
total_specific_opposition_reps<-c(27.53, 31.43, 40.72, 29.47, 30.45, 22.52, 33.36, 52.68, 43.48, 36.56, 51.24, 39.84, 41.2,47.57,39.71, 54.10, 52.79, 54.10, 43.87, 62.89, 47.33, 58.05, 60.74, 60.66, 55.47, 57.99, 40.48, 59.89, 45.33, 56.47, 47.88, 56.05, 35.58, 44.00, 40.68, 49.72, 41.07, 43.79, 44.00, 46.66, 42.10, 50.23, 48.10, 73.22, 63.76, 58.97, 50.72, 57.08, 53.54, 59.4, 54.19, 45.26, 51.83, 56.46, 51.11, 67.52, 53.66, 60.37, 50.63)
par(mfrow=c(1,2))

plot(-1,-1, xlim=c(0,60), ylim=c(20, 75), main="Democrats", xlab="Wave", ylab="Percent",axes=F)
axis(1, at=c(2, 8,14,20, 26,32,38,44,50,56), lab=c("1/12", "7/12","1/13","7/13", "1/14","7/14","1/15","7/15","1/16","7/16"))
axis(2, at=c(20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75), lab=c("20","25", "30","35","40","45", "50", "55", "60", "65", "70", "75"))

lines(months , total_specific_support_dems, lty=1, col="blue")
lines(months , total_specific_opposition_dems, lty=2, col="blue")
legend(25, 75, c("Approve", "Disapprove"), lty=c(1,2), col=c("blue"))
box()


plot(-1,-1, xlim=c(0,60), ylim=c(20, 75), main="Republicans", xlab="Wave", ylab="Percent",axes=F)
axis(1, at=c(2, 8,14,20, 26,32,38,44,50,56), lab=c("1/12", "7/12","1/13","7/13", "1/14","7/14","1/15","7/15","1/16","7/16"))
axis(2, at=c(20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75), lab=c("20","25", "30","35","40","45", "50", "55", "60", "65", "70", "75"))

lines(months , total_specific_support_reps, lty=1, col="red")
lines(months , total_specific_opposition_reps, lty=2, col="red")
legend(25, 75, c("Approve", "Disapprove"), lty=c(1,2), col=c("red"))
box()

